package com.qcby.llmtchstd.service.Impl;

import com.qcby.llmtchstd.common.ResponseResult;
import com.qcby.llmtchstd.dao.AdminDao;
import com.qcby.llmtchstd.entity.Admin;
import com.qcby.llmtchstd.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;

    @Override
    public ResponseResult login(Admin admin) {
        try{
            Admin temp=adminDao.login(admin.getName());

            if(temp==null){
                //账户错误
                return ResponseResult.fail("4001","账户错误");
            }
            if(temp.getPassword().equals(admin.getPassword())){
                temp.setPassword("*********");
                return ResponseResult.success("登录成功",temp);
            }
            return ResponseResult.fail("4002","密码错误");
        }
        catch (Exception e) {
            e.printStackTrace();//打印异常到控制台
            return ResponseResult.dbError("数据库异常：登录失败");
        }
    }

    @Override
    public Admin adminCurrent(int id) {
        return adminDao.adminCurrent(id);
    }
}